package com.fupeng.leetCode;

import static org.junit.Assert.*;

import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

public class Wordbreak {
	@Test
	public void testName() throws Exception {
		Set<String> set = new HashSet<String>();
		set.add("a");
//		set.add("code");
		System.out.println(wordBreak("a", set));
	}
    public boolean wordBreak(String s, Set<String> dict) {
    	if(s==null)
    		return true;
        for(int i=1;i<=s.length();i++){
        	String left = s.substring(0, i);
        	String right = s.substring(i, s.length());
        	if("".equals(left)&&dict.contains(right)
        			||"".equals(right)&&dict.contains(left)
        			||dict.contains(left)&&dict.contains(right))
        		return true;
        }
        return false;
    }
}
